package homework;
//作业标题(2301)
//单链表的逆置
//
//作业内容
//单链表的逆置
//https://leetcode.cn/problems/reverse-linked-list/submissions/
public class h2301 {

    class ListNode {
          int val;
          ListNode next;
          ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }
      }

    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null) return head;

        ListNode cur = head.next;
        head.next = null;
        while(cur.next != null)
        {
            ListNode curNext = cur.next;
            cur.next = head;
            head = cur;
            cur = curNext;
        }

        return head;
    }
}
